import request from '@/utils/request'

const base_api = '/admin/system/role'
const binding_api = '/admin/system/roleMenu'

// 分页查询角色列表
export const GetSysRoleListByPage = (pageNum, pageSize, queryDto) => {
  return request({
    // url: '/admin/system/role/findByPage/' + pageNum + "/" + pageSize,
    url: `${base_api}/findByPage/${pageNum}/${pageSize}`,
    method: 'post',
    data: queryDto,
  })
}

// 查询所有的角色数据
export const GetAllRoleList = userId => {
  return request({
    url: `${base_api}/findByUserId/${userId}`,
    method: 'get',
  })
}

// 添加角色
export const SaveSysRole = sysRole => {
  return request({
    url: `${base_api}/saveSysRole`,
    method: 'post',
    data: sysRole,
  })
}

// 修改角色
export const UpdateSysRole = sysRole => {
  return request({
    url: `${base_api}/updateSysRole`,
    method: 'put',
    data: sysRole,
  })
}

// 删除角色
export const DeleteSysRole = roleId => {
  return request({
    url: `${base_api}/deleteById/${roleId}`,
    method: 'delete',
  })
}

// 根据角色id查询对应的菜单id列表
export const GetSysRoleMenuIds = roleId => {
  return request({
    url: `${binding_api}/findSysRoleMenuByRoleId/${roleId}`,
    method: 'get',
  })
}

// 角色分配菜单
export const DoAssignMenuIdToSysRole = assignMenuDto => {
  return request({
    url: `${binding_api}/doAssign`,
    method: 'post',
    data: assignMenuDto,
  })
}
